import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:tiktokadult/routers/jump_router.dart';
import 'package:tiktokadult/tools_base/widget/net_image_widget.dart';

import '../../../hj_model/splash/ads_model.dart';
import '../../../hj_model/video_model.dart';
import '../../find/pic_collect/pics_detail_page.dart';

class PicSimpleCellWidget extends StatelessWidget {
  final VideoModel? videoModel;
  final int? index;
  final bool isEditStatus; // 编辑模式
  final int textLines;
  const PicSimpleCellWidget({
    super.key,
    this.videoModel,
    this.index,
    this.isEditStatus = false,
    this.textLines = 2,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => Get.to(PicsDetailPage(id: videoModel?.id), preventDuplicates: false),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: Stack(
              fit: StackFit.expand,
              children: [
                NetworkImageLoader(
                  imageUrl: videoModel?.cover ?? '',
                  borderRadius: 8,
                  alignment: Alignment.topCenter,
                ),
                Positioned(
                  left: 0,
                  right: 0,
                  bottom: 0,
                  child: Container(
                    padding: EdgeInsets.fromLTRB(6, 8, 6, 6),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Colors.black.withOpacity(0),
                          Colors.black.withOpacity(0.6),
                        ],
                      ),
                    ),
                    child: Row(
                      children: [
                        Image.asset("count_eye.png".communityPath, width: 14),
                        1.sizeBoxW,
                        Text(
                          "${videoModel?.playCount?.humanizeFormat}",
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(color: Colors.white, fontSize: 10),
                        ),
                        Spacer(),
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 4, vertical: 1),
                          // decoration: BoxDecoration(color: Colors.black.withOpacity(0.6), borderRadius: BorderRadius.circular(4)),
                          child: Row(
                            children: [
                              Image.asset(
                                "icon_pic.png".communityPath,
                                width: 10,
                                height: 10,
                              ),
                              2.sizeBoxW,
                              Text(
                                videoModel?.seriesCover?.length.toString() ?? "",
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 8,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                if (isEditStatus)
                  Container(
                    color: Colors.black.withOpacity(0.6),
                    padding: EdgeInsets.only(top: 6, right: 6),
                    alignment: Alignment.topRight,
                    child: Image.asset(
                      videoModel?.isSelected == true ? "selected_green.webp".commonImgPath : "empty_circle.webp".commonImgPath,
                      width: 24,
                      height: 24,
                    ),
                  ),
              ],
            ),
          ),
          Container(
            padding: const EdgeInsets.only(top: 4),
            child: Text(
              "${videoModel?.title ?? ""}\n",
              maxLines: textLines,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: Colors.white,
                fontSize: 14,
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildPriceItem() {
    if (videoModel?.permission == 2) {
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topRight: Radius.circular(8),
            bottomLeft: Radius.circular(8),
          ),
          gradient: LinearGradient(
            colors: [
              Color(0xffADFCAC),
              Color(0xff5CEF97),
            ],
          ),
        ),
        child: Text(
          "免费",
          style: TextStyle(
            color: Colors.black,
            fontSize: 10,
          ),
        ),
      );
    }
    if (videoModel?.permission == 1) {
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 6, vertical: 3),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topRight: Radius.circular(8),
            bottomLeft: Radius.circular(8),
          ),
          gradient: LinearGradient(
            colors: [
              Color(0xffDB361F),
              Color(0xffDB361F),
            ],
          ),
        ),
        child: Image.asset("coin.webp".commonImgPath, width: 14, height: 14),
      );
    }
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.only(
          topRight: Radius.circular(8),
          bottomLeft: Radius.circular(8),
        ),
        gradient: LinearGradient(
          colors: [
            Color(0xffF6CBB8),
            Color(0xffEEB4AA),
          ],
        ),
      ),
      child: Text(
        "VIP",
        style: TextStyle(
          color: Colors.black,
          fontSize: 12,
        ),
      ),
    );
  }
}

class VideoSimpleAdsCellWidget extends StatelessWidget {
  final AdsInfoModel? videoModel;

  const VideoSimpleAdsCellWidget({
    super.key,
    this.videoModel,
  });

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        pushToPageByLink(videoModel?.href, id: videoModel?.id);
      },
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: NetworkImageLoader(
              imageUrl: videoModel?.cover ?? "",
              borderRadius: 8,
            ),
          ),
          Container(
            padding: const EdgeInsets.only(top: 6, bottom: 3),
            child: Text(
              videoModel?.title ?? "",
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: Colors.white,
                fontSize: 12,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
